<template>
  <column :options="options" v-model:reduced="columns" />
</template>
<script setup>
import { ref, onMounted } from 'vue'
import column from '@/components/icon-column-select/icon-column-select.vue'
import { useColumns } from './provide-context.js'
import { operationList } from '@/api/log.js'
import { message } from 'ant-design-vue'

let columns = useColumns()
onMounted(async () => {
  try {
    let res = await operationList()
    if (res.data) {
      columns.value.forEach(e => {
        if (e.key === 'operationModule') {
          e.filters = res.data
        }
      })
    }
  } catch (e) {
    message.error('获取操作对象列表失败')
  }
})
let options = ref([
  {
    title: '编号',
    dataIndex: 'id',
    fixed: 'left',
    key: 'id',
    width: 100,
  },
  {
    title: '操作用户名',
    dataIndex: 'userName',
    key: 'userName',
    fixed: 'left',
    width: 100,
    // filters: [
    //   { text: '系统管理员', value: 'system' },
    //   { text: '安全管理员', value: 'security' },
    //   { text: '普通用户', value: 'normal' },
    // ],
  },
  {
    title: '操作的对象',
    dataIndex: 'operationModule',
    key: 'operationModule',
    width: 100,
    filters: [],
    filterMultiple: false,
    filteredValue: null,
  },
  {
    title: '进行的操作',
    dataIndex: 'action',
    key: 'action',
    width: 100,
  },

  {
    title: '操作时间',
    dataIndex: 'createdTime',
    key: 'createdTime',
    sorter: true,
    // sortOrder: undefined,
    width: 140,
  },
  {
    title: '客户端ip',
    dataIndex: 'remoteAddr',
    key: 'remoteAddr',
    width: 120,
  },
  {
    title: '服务器ip',
    dataIndex: 'requestIp',
    key: 'requestIp',
    width: 120,
  },
  {
    title: '请求是否成功',
    dataIndex: 'accessSuccess',
    key: 'accessSuccess',
    // filters: [
    //   { text: '是', value: true },
    //   { text: '否', value: false },
    // ],
    // filterMultiple: false,
    // filteredValue: null,
    width: 110,
  },
  {
    title: '请求耗时(秒)',
    dataIndex: 'accessDuration',
    key: 'accessDuration',
    width: 100,
  },
  {
    title: '操作详情',
    dataIndex: 'operationMsg',
    key: 'operationMsg',
    width: 100,
  },
])
</script>
